
const Service = require('egg').Service;
const axios = require('axios');
//axios 用法：https://www.npmjs.com/package/axios
class curlService extends Service {
    async curlPost(curl,param)  {
        let res_param=""
        const {ctx,logger} = this;
        try{
            const result = await ctx.curl('http://api.tl100.com/bookex/'+curl, {
                method: 'POST',
                contentType: 'json',
                data: param,
                dataType: 'json',
            });
            ctx.status = result.status;
            if (ctx.status == 200) {
                res_param=result.data
            }else{
                res_param={res_code: -1, msg: "empty"}
            }

        }catch(err){
            logger.error('Access curl error', err);
            res_param=err
        }
        return res_param
    }
}
module.exports = curlService;